﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using JasRibbonApplicatie.Classes;
using JasRibbonApplicatie.UserControls;
using JasRibbonApplicatie.Model;

namespace JasRibbonApplicatie.Views.BeheerAanvragen
{
    /// <summary>
    /// Interaction logic for MailsAanvragen.xaml
    /// </summary>
    public partial class MailsAanvragen : Page
    {
        private Login login = null;
        private MainWindow mainWindowReference = null;
        private List<Email> mails = new List<Email>();
        private MailItemControl current_mail = null;
        private static GebruikerModel gm = new GebruikerModel();

        public MailsAanvragen()
        {
            InitializeComponent();

            login = Login.Instance;
            mainWindowReference = login.MainWindowReference;
            mainWindowReference.AanvragenToolsGroup.Visibility = Visibility.Visible;
            mainWindowReference.MailToolsGroup.Visibility = Visibility.Visible;
            mainWindowReference.AanvragenSelectieGroup.Visibility = Visibility.Collapsed;
            loadMails(5);
        }

        private void loadMails(int id)
        {
            mails = gm.GetMails(id);

            mailsListbox.Items.Clear();
            foreach (var mail in mails)
                mailsListbox.Items.Add(new MailItemControl(mail));

        }

        public void NewMail()
        {

            MailWindow mw = new MailWindow();
            mw.Show();
        }


        private void newMailWindow(string to = "", string subject = "", string body = "", string attachment = "", string cc = "", string bcc = "")
        {

        }

        private void mailsListbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MailItemControl eml = (sender as ListBox).SelectedItem as MailItemControl;
            if (current_mail == null)
            {
                eml.startSeing();
                current_mail = eml;
            }
            else if (current_mail.Email.email_fingerprint_auto != eml.Email.email_fingerprint_auto)
            {
                current_mail.stopSeing();
                eml.startSeing();
                current_mail = eml;
            }
            mailHtmlviewer.ContentHtml = eml.Email.html;
        }

    }
}
